View Javadoc

1   /*
2    * Copyright (c) 2004-2005, University Health Network.  All rights reserved. Distributed under the BSD 
3    * license (see http://opensource.org/licenses/bsd-license.php).
4    *  
5    * DateTimeUtil.java
6    *
7    * Created on 20-Dec-2004 at 4:40:28 PM
8    */
9   package ca.uhn.cache.internal.util;
10  
11  import java.sql.Timestamp;
12  import java.util.Date;
13  
14  
15  /***
16   * Group utility to handle converions between <code>java.util.Date</code> and <code>java.sql.TimeStamp</code>.  
17   * 
18   * @author <a href="mailto:alexei.guevara@uhn.on.ca">Alexei Guevara</a>
19   * @version $Revision: 1.1 $ updated on $Date: 2005/01/24 22:53:24 $ by $Author: bryan_tripp $
20   */
21  public final class TimestampUtils {
22  
23      /***
24       */
25      private TimestampUtils() {
26          super();
27      }
28      
29      /***
30       * Converts a date to a time stamp.
31       *  
32       * @param theDate The source date.
33       * @return The corresponding time stamp.
34       * 
35       * @see Timestamp
36       */
37      public static final Timestamp dateToTimestamp( Date theDate ) {
38          Timestamp retVal = new Timestamp( theDate.getTime() );
39          
40          assert retVal.getNanos() == 0 : "retVal.getNanos() == 0 (use UTC.currentTime())";
41          
42          return  retVal;
43      }
44      
45      /***
46       * Converts a time stamp to a date.
47       * 
48       * @param theTimestamp The source time stamp.
49       * @return The corresponding date.
50       * 
51       * @see Timestamp 
52       */
53      public static final Date timestampToDate( Timestamp theTimestamp ) {
54          Date retVal = new Date( theTimestamp.getTime() );
55          return retVal;
56      }
57      
58  
59  }